/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.frm.bpm.pojo;

import java.io.Serializable;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Collection;

/**
 *
 * @author Kenn
 */
public class Receivables implements Serializable {

    private Timestamp date;
    private String month;
    private Double amount;
    private SimpleDateFormat sdf = new SimpleDateFormat("MMM yyyy");

    public Receivables(Timestamp date, Collection<FutureTransaction> transactions) {
        this.date = date;
        amount = 0.0D;
        populate(transactions);
    }

    private void populate(Collection<FutureTransaction> transactions) {

        month = sdf.format(date);
        
        for (FutureTransaction t : transactions) {

            Timestamp tDate = t.getTransactionDate();
            if (date.getYear() == tDate.getYear()
                    && date.getMonth() == tDate.getMonth()
                    && date.getDay() == tDate.getDay()) {

                if (t.getCashDebit() != null && t.getCashDebit() != 0.0D) {
                    amount += t.getCashDebit();
                }              
            }
        }
    }

    public Double getAmount() {
        return amount;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public Timestamp getDate() {
        return date;
    }

    public void setDate(Timestamp date) {
        this.date = date;
    }

    public String getMonth() {
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }
    
}
